
本篇介紹 ES2019 (ES10) 提供的 optional catch binding。
想省略 catch binding 的情境:
catch binding有可能你會想這樣寫,讓 catch 的括號內不寫參數,但這樣會產生 SyntaxError 錯誤:
try {
func();
} catch () {
// ...
}
// SyntaxError: Unexpected token ')'
因為 catch 的 spec 定義如下:括號內一定要有 CatchParameter,不能只有空的括號
此提案允許省略 catch binding 和旁邊的括號:
try {
// ...
} catch {
// ...
}